package rrrmai.room.dao;

import android.arch.lifecycle.LiveData;
import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Delete;
import android.arch.persistence.room.Insert;
import android.arch.persistence.room.OnConflictStrategy;
import android.arch.persistence.room.Query;
import android.arch.persistence.room.Update;
import java.util.List;
import io.reactivex.Flowable;
import rrrmai.viewbinder.Post;
import static android.arch.persistence.room.OnConflictStrategy.REPLACE;

/**
 * Created by summer on 2018/3/20.
 */
@Dao
public interface PostDao {
    @Insert(onConflict = OnConflictStrategy.REPLACE)
     Long[] insertPostList(List<Post> post);
     //rowId
    @Insert(onConflict = OnConflictStrategy.REPLACE)
     Long[] insertPost(Post... post);
    //rowNums
    @Update
     int updatePost(Post... post);
    //rowNums
    @Delete
     int  deletePost(Post... post);

    @Query("SELECT p.*,c.mobile as userMobile,c.name as userName FROM post p left join contact c on p.userId=c.id ORDER BY rowsNum desc")
    Flowable<List<Post>> loadAll();

    @Query("SELECT * from post where id = :id LIMIT 1 ")
     Flowable<Post> loadById(int id);

    @Query("SELECT * from post where userId = :userId")
    Flowable<List<Post>> loadByUserId(int userId);

    @Query("SELECT * FROM post ORDER BY `rowid` limit :pageSize offset :limitRows")
    Flowable<List<Post>> loadByPage(int limitRows,int pageSize);


    //@Insert
    //public void insertUsersAndFriends(User user, List<User> friends);

  /*  @Query("SELECT first_name, last_name FROM user WHERE region IN (:regions)")
    public LiveData<List<User>> loadUsersFromRegionsSync(List<String> regions);*/



}
